package com.hanter.downloader.service;

import android.content.Context;
import android.net.Uri;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.hanter.downloader.Downloader;
import com.hanter.downloader.TaskInfo;

import java.io.File;
import java.io.FileDescriptor;
import java.io.IOException;

public interface DownloadService {

    void updateConfig(Downloader.Config config);

    @Nullable
    TaskInfo getTaskInfo(@NonNull String url);

    boolean isContentRangeSupported(@NonNull String url);

    /**
     * 从偏移位置开始下载，前提支持 断点下载
     *
     * @param file   保存的文件
     * @param start
     * @return
     */
    long download(@NonNull File file, @NonNull String url, long start, long end,
                  @Nullable OnProgressIncreaseListener listener) throws IOException, InterruptedException;

    long download(@NonNull FileDescriptor fd, @NonNull String url, long start, long end,
                  @Nullable OnProgressIncreaseListener listener) throws IOException, InterruptedException;

    long download(@NonNull Context context, @NonNull Uri uri, @NonNull String url, long start,
                  long end, @Nullable OnProgressIncreaseListener listener) throws IOException, InterruptedException;

    /**
     * 对于不支持断点下载，就直接下载全部
     *
     * @param file
     */
    long download(@NonNull File file, @NonNull String url, @Nullable OnProgressIncreaseListener listener) throws IOException, InterruptedException;

}
